﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
namespace GUI
{
    public partial class FrmChuyenBan : Form
    {
        BanBUS banBUS = new BanBUS();
        ChiTietHoaDonBUS cthdBUS = new ChiTietHoaDonBUS();
        public FrmChuyenBan()
        {
            InitializeComponent();
            Load_dsBan_CuvsMoi();
        }
        public void Load_dsBan_CuvsMoi()
        {
            //load ds ban cu
            cbBanCu.DataSource = banBUS.LayBanTheoTrongNgayChuaThanhToan();
            cbBanCu.DisplayMember = "MaBan";
            cbBanCu.ValueMember = "MaBan";
            //load ds ban moi
            cbBanMoi.DataSource = banBUS.laydanhsachbantheotrangthai("Trống");
            cbBanMoi.DisplayMember = "MaBan";
            cbBanMoi.ValueMember = "MaBan";
        }
        private void btnDongY_Click(object sender, EventArgs e)
        {
            string MaBanCu = cbBanCu.SelectedValue.ToString();
            string MaBanMoi = cbBanMoi.SelectedValue.ToString();        
            if(cthdBUS.CapNhatMaBanChiTietHoaDon(MaBanCu, MaBanMoi)==1)
            {
                BanBUS banBUS = new BanBUS();
                BanDTO bn = new BanDTO();
                bn.MaBan = MaBanMoi;
                bn.TrangThai = "Bận";
                banBUS.CapNhatBan(bn);
                //cập nhật lại trạng thái bàn 
                bn.MaBan = MaBanCu;
                bn.TrangThai = "Trống";
                banBUS.CapNhatBan(bn);
                MessageBox.Show("Chuyển Bàn Thành Công!");
                Load_dsBan_CuvsMoi();
                return;
            }
            else
            {
                MessageBox.Show("Chuyển Bàn Thất Bại!");
                return;
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmChuyenBan_FormClosed(object sender, FormClosedEventArgs e)
        {
            Program.frm_manhinhchinh.sub_mn_ChuyenBan.Checked = false;
        }

        private void FrmChuyenBan_Load(object sender, EventArgs e)
        {

        }


    }
}
